package cn.itcast.bos.service.base.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.base.IStandardRepository;
import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.service.base.IStandardService;

@Service
@Transactional
public class StandardServiceImpl implements IStandardService {

    // 注入dao
    @Autowired
    private IStandardRepository standardRepository;

    // 添加收派标准
    @Override
    // 清空缓存standard(shcash.xml)
    @CacheEvict(value = "standard", allEntries = true)
    public void saveStandard(Standard standard) {
        // TODO Auto-generated method stub
        System.out.println("添加数据，清空缓存");
        standardRepository.save(standard);
    }

    // 分页列表查询
    @Override
    // 将查询到的分页数据根据pageNumber，pageSize缓存到standard(shcash.xml)
    @Cacheable(value = "standard", key = "#pageable.pageNumber+'_'+#pageable.pageSize")
    public Page<Standard> pageQueryStandard(Pageable pageable) {
        // TODO Auto-generated method stub
        System.out.println("分页缓存");
        return standardRepository.findAll(pageable);
    }

    // 查询所有收派信息
    @Override
    // 将查询到的数据缓存到standard(shcash.xml)
    @Cacheable("standard")
    public List<Standard> findAllStandard() {
        // TODO Auto-generated method stub
        System.out.println("全部查询缓存");
        return standardRepository.findAll();
    }

}
